﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SharedGenomics.Core;

namespace SharedGenomics.Domain
{
    public class IndividualGenotypeCollection : IEnumerable<IndividualGenotype>
    {
        private IDictionary<string, IndividualGenotype> _individuals;

        public IndividualGenotypeCollection()
        {
            this.Markers = new HashSet<string>();
            this._individuals = new Dictionary<string, IndividualGenotype>();
        }

        public bool TryGetIndividual(string id, out IndividualGenotype genotype)
        {
            if (id == null)
            {
                genotype = null;
                return false;
            }

            return this._individuals.TryGetValue(id, out genotype);
        }

        public bool Contains(string id)
        {
            return id != null && this._individuals.ContainsKey(id);
        }

        public ICollection<string> Markers { get; private set; }

        public IndividualGenotype this[string id]
        {
            get { return this._individuals[id]; }
            set
            {
                id.ThrowIfNull("id");
                this._individuals[value.Id] = value;
            }
        }

        public int Count
        {
            get { return this._individuals.Count; }
        }

        public IEnumerator<IndividualGenotype> GetEnumerator()
        {
            return this._individuals.Values.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}
